#include "loger.h"
#include "debug.h"
#include <math.h>

#pragma pack(4)
typedef struct test1{
	uint32_t a ;
	uint32_t b;
	char c;
}Test1;
#pragma pack()

#pragma pack(1)
typedef struct testsize2{
	uint16_t a;
	uint8_t b;
	uint32_t c;
}Test2;
#pragma pack()

// 限制float有效位
float LimitFloat(float in,int size){
	uint64_t tmp =  1;
	for(int i = 0;i < size;i++){
		tmp = tmp*10;
	}
	uint64_t integer = uint64_t(in * tmp);  // 提取整数部分

	uint64_t decimal = integer %tmp; // 提取小数部分
	std::cout<< "float_limit " << in<< " "<< integer << "  "<< decimal <<  "  "<< tmp <<std::endl;

	return float(integer)/tmp;
}

typedef enum{
    BIG_ENDIAN = 1,  // 大端
    LITTLE_ENDIAN // 小端
}BYTE_ORDER;

BYTE_ORDER HostByteOrder(){
    short x = 0x1234;
    uint8_t y = *((uint8_t*)(&x));
    if(y == 0x34){
        return BYTE_ORDER::LITTLE_ENDIAN;
    }else{
        return BYTE_ORDER::BIG_ENDIAN;
    }
}


int main(){
	std::cout<<"byteorder "<<HostByteOrder()<<std::endl;
	std::cout<< LimitFloat(1.123,2)<<std::endl;
	std::cout<<LimitFloat(1.123,3) << std::endl;
	std::cout<<LimitFloat(0.789,1) << std::endl;
	std::cout<<LimitFloat(0,3) << std::endl;

	std::cout<<"\r\n"<<std::endl<<sizeof(Test1) << " "<<  sizeof(Test2)<<std::endl;
	Test1 x = Test1{
		1,2,3
	};
	Test2 y = Test2{
		1,2,3
	};
	char result[1000] = {0};
	PrintDumpObjvoid(&x,6,sizeof(Test1),false);
	dumpObj(&y,6,sizeof(Test2),true,result);
	std::cout<<result<<std::endl;

	Loger loger1("d://","test",true);
	loger1.SetMinimalLevel(LEVEL_DEBUG);
	loger1.Debug("hello",FILE_POSITION);
	loger1<< "12131";
	loger1 + "12121";
	loger1.Debug("hello11212",FILE_POSITION);
}



